// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Grass Fireball Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 41 : TYPE_GRASSFIREBALL


// Static Values

// Tables

event ObjectMain
	switch object.state
	case 0
		temp0 = object.value2
		temp0 >>= 1
		switch object.value3
		case 0
			GetTableValue(object.ypos, temp0, LargePlatform_table27)
			object.ypos <<= 16
			object.value4 = 7
			break
		case 1
			GetTableValue(object.ypos, temp0, LargePlatform_table28)
			object.ypos <<= 16
			object.value4 = 7
			break
		case 2
			object.ypos = -0x300000
			object.value4 = 3
			break
		end switch
		arrayPos0 = object.value1
		object.ypos += object[arrayPos0].value1
		if object.propertyValue == 0
			CreateTempObject(TypeName[Grass Fireball], object.propertyValue, object.xpos, object.ypos)
			object[tempObjectPos].propertyValue++
			object[tempObjectPos].value1 = object.value1
			object[tempObjectPos].drawOrder = 5
			object[tempObjectPos].value2 = object.value2
			object[tempObjectPos].value3 = object.value3
			object[tempObjectPos].value4 = object.value4
			object[tempObjectPos].state = 1
			object[tempObjectPos].animationTimer = object.animationTimer
			object.animationTimer = 0
			object.state = 2
			PlaySfx(SfxName[Fire Burn], 0)
		else
			object.state++
		end if
		break
	case 1
		object.value0++
		object.xpos += 0x10000
		object.value2++
		temp0 = object.value2
		temp0 >>= 1
		switch object.value3
		case 0
			GetTableValue(object.ypos, temp0, LargePlatform_table27)
			object.ypos <<= 16
			break
		case 1
			GetTableValue(object.ypos, temp0, LargePlatform_table28)
			object.ypos <<= 16
			break
		case 2
			object.ypos = -0x300000
			break
		end switch
		arrayPos0 = object.value1
		object.ypos += object[arrayPos0].value1
		if object.value0 == 16
			object.state++
			if object.propertyValue < object.value4
				CreateTempObject(TypeName[Grass Fireball], object.propertyValue, object.xpos, object.ypos)
				object[tempObjectPos].propertyValue++
				object[tempObjectPos].value1 = object.value1
				object[tempObjectPos].drawOrder = 5
				object[tempObjectPos].value2 = object.value2
				object[tempObjectPos].value3 = object.value3
				object[tempObjectPos].value4 = object.value4
				if object.propertyValue == 7
					object[tempObjectPos].state = 2
				else
					object[tempObjectPos].state = 1
				end if
				object[tempObjectPos].animationTimer = object.animationTimer
				object.animationTimer = 0
				PlaySfx(SfxName[Fire Burn], 0)
			end if
		end if
		break
	case 2
		temp0 = object.value2
		temp0 >>= 1
		switch object.value3
		case 0
			GetTableValue(object.ypos, temp0, LargePlatform_table27)
			object.ypos <<= 16
			break
		case 1
			GetTableValue(object.ypos, temp0, LargePlatform_table28)
			object.ypos <<= 16
			break
		case 2
			object.ypos = -0x300000
			break
		end switch
		arrayPos0 = object.value1
		object.ypos += object[arrayPos0].value1
		break
	end switch
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -6, -14, 6, 14, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		if checkResult == 1
			CallFunction(PlayerObject_FireHit)
		end if
	next
	object.frame = object.animationTimer
	object.frame /= 12
	object.direction = object.animationTimer
	object.direction /= 6
	object.direction &= FLIP_X
	object.animationTimer++
	object.animationTimer %= 24
	arrayPos0 = object.value1
	if object[arrayPos0].outOfBounds == 1
		object.type = TypeName[Blank Object]
		object[arrayPos0].value3 = 0
	end if
end event


event ObjectDraw
	DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
end event


event ObjectStartup
	LoadSpriteSheet("MZ/Objects.gif")
	SpriteFrame(-7, -23, 15, 31, 52, 114)
	SpriteFrame(-8, -24, 16, 32, 68, 114)
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
